home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / boostrs.arc / TBX.ASM < prev    next >
Encoding:
Assembly Source File  |  1980-01-01  |  3.8 KB  |  186 lines

  1. ;************************************************
  2. ;
  3. ;    Procedure Exec ( Var FileDesc,
  4. ;                         ComLine  : AnyString;
  5. ;                     Var Code     : Integer );
  6. ;
  7. ;***********************************************
  8. EXEC    proc
  9.     push    bp
  10.     mov    bp,sp
  11.     push    ds
  12. ;
  13.     Call    Get_IP    ; copy IP from stack to BX
  14.         jmp     start   ; IP will point here
  15. ORGSP    dw    (0)
  16. ORGSS    dw    (0)
  17. Savoff    dw    (0)
  18. parm    db    14 dup(0)    ; needed by EXEC call
  19. CMDLin    db    127 dup(0)    ; DOS command line
  20. fcb1    db    37 dup(0)    ; an FCB
  21. fcb2    db    37 dup(0)    ; another FCB
  22. Pgm2X    db    45 dup(0)    ; program to invoke
  23. Ecode    dw    (0)        ; error code
  24. ;
  25. start:    add    bx,3    ; adjust BX to -> ORGSP
  26.     mov    cs:[bx],sp    ; save SP in ORGSP
  27.     mov    cs:[bx+2],ss    ; save SS
  28.     mov    word ptr cs:[bx+266],0
  29.     push    bx    ; save BX
  30. ;
  31. ;
  32. ;       *** Shrink
  33. ;  ES has block segment,
  34. ;  BX has block size in paragraphs
  35. ;  AL errors are 7,8,and 9
  36. ;
  37.     push    cs
  38.     pop    es
  39.     mov    bx,0FFFh
  40.     mov    ah,4Ah
  41.     int    21h
  42. ;
  43.     cmp    ax,10
  44.     ja    t000
  45.     pop    bx
  46.     mov    cs:[bx+266],ax
  47.     jmp    error
  48. ;
  49. t000:    call    Get_IP
  50.     jmp    t001
  51. SaveA    db    100 dup(0)
  52. t001:    add    bx,3
  53.     pop    di
  54.     mov    cs:[di+4],bx    ; offset SaveA
  55.     push    di
  56.     mov    di,bx
  57.     mov    ax,cs    ; segment of blk
  58.     mov    es,ax
  59.     mov    cx,0FFFFh
  60.     sub    cx,sp
  61.     cmp    cx,100
  62.     jna    t002
  63.     pop    bx
  64.     mov    cs:[bx+266],19    ; ecode
  65. error:    jmp    leave    ; stack too big to save
  66. t002:    mov    dx,ss
  67.     mov    ds,dx
  68.     mov    si,sp
  69.         cld
  70. rep     movsb           ; save stack
  71. ;
  72. ;       *** Create EXEC control block
  73. ;   Format is:
  74. ;       Segment Address of Environ string (2)
  75. ;       Segmented ptr to command line     (4)
  76. ;       Segmented ptr to 1st default FCB  (4)
  77. ;       Segmented ptr to 2nd default FCB  (4)
  78. ;   Total length, 14 bytes.
  79. ;
  80. ;
  81.     pop    bx
  82.     mov    ax,cs:[2Ch]    ; PSP envir str
  83.     mov    word ptr cs:[bx+6],ax
  84.     lea    cx,[bx+20]
  85.     mov    cs:[bx+8],cx    ; CMDLine offset
  86.     mov    cs:[bx+10],cs    ; . . and segment
  87.     lea    cx,[bx+147]    ; FCB1 offset
  88.     mov    cs:[bx+12],cx    ; . . save it
  89.     mov    cs:[bx+14],cs    ; . . save segment
  90.     lea    cx,[bx+184]    ; FCB2 offset
  91.     mov    cs:[bx+16],cx    ; . . save it
  92.     mov    cs:[bx+18],cs    ; . . save segment
  93. ;
  94. ;       ** Move Filedesc from stack
  95. ;          to code segment
  96. ;
  97.     mov    si,[bp+12]    ; str offset
  98.     mov    ds,[bp+14]    ; str segment
  99.     mov    cl,[si] ; len of FileDesc
  100.     xor    ch,ch
  101.     inc    si
  102.     push    cs
  103.     pop    es
  104.     mov    di,bx
  105.     add    di,221        ; Pgm2X
  106.     mov    dx,di
  107.     cld
  108. rep    movsb        ; move Filedesc
  109.     mov    byte ptr es:[di],0
  110. ;
  111. ;       ** Move Command Line from stack
  112. ;          to code segment
  113. ;
  114.     mov    si,[bp+08]    ; offset
  115.     mov    ds,[bp+10]    ; segment
  116.     mov    cl,[si] ; length of Com str
  117.     inc    si
  118.     mov    di,bx
  119.     add    di,20        ; ComLin
  120. rep    movsb        ; move Command Ln
  121.     mov    byte ptr es:[di],0Dh
  122. ;
  123. ;       *** Load & Execute,
  124. ;           then come back.
  125. ;  AL = 0 for load & execute
  126. ;  AH = 4B for EXEC call
  127. ;  DS:DX points to AsciiZ of filedesc
  128. ;  ES:BX points to parm block
  129. ;
  130.     mov    cx,cs
  131.     mov    ds,cx
  132.     mov    ss,cx
  133.     mov    al,0
  134.     mov    ah,4Bh
  135.     mov    di,bx
  136.     call    Get_IP
  137.     mov    cs:[bx+12],di
  138.     mov    bx,di
  139.     add    bx,6
  140.     int    21h
  141. ;
  142.     mov    bx,0000 ; BX -> ORGSP
  143.     jnc    AOK
  144.     mov    cs:[bx+266],ax    ; Save AX
  145. AOK:    mov    dx,bx        ; Save BX
  146.     mov    bx,0FFFFh    ; blks to grow
  147.     mov    ah,4Ah        ; 'grow' function
  148.     mov    cx,cs        ; ES will contain . .
  149.     mov    es,cx        ; the blk segment
  150.     int    21h        ; This will fail . .
  151.     mov    ah,4Ah        ; but BX will have . .
  152.     int    21h        ; the maximum size
  153.     mov    bx,dx        ; restore -> ORGSP
  154.     mov    sp,cs:[bx]    ; restore SP
  155.     mov    di,sp        ; setup for move
  156.     mov    ax,cs:[bx+2]    ; restore SS
  157.         mov     ss,ax
  158.     mov    es,ax        ; ES:DI set
  159.     mov    si,cs:[bx+4]    ; get offset of . .
  160.     add    si,2        ; stack save area
  161.     mov    ax,cs
  162.     mov    ds,ax        ; DS:SI set
  163.     mov    cx,0FFFFh    ;
  164.     sub    cx,sp        ; length of stack
  165.     cld
  166. rep    movsb            ; restore stack
  167.  
  168. ;
  169. Leave:
  170.     pop    ds
  171.     mov    bp,sp
  172.     mov    di,[bp+4]    ; Ecode offset
  173.     mov    es,[bp+6]    ; Ecode segment
  174.     mov    ax,cs:[bx+266]    ; Ecode setting
  175.     mov    es:[di],ax    ; set Ecode
  176.     pop    bp
  177. ;
  178.     ret    12
  179. EXEC    endp
  180. ;
  181. Get_IP  proc
  182.     mov    bx,sp
  183.     mov    bx,ss:[bx]
  184.     ret
  185. Get_IP    endp
  186.